package cn.wj.school.app;

import cn.wj.school.app.net.client.ClientNet;
import cn.wj.school.app.ui.view.StageView;
import cn.wj.school.common.controller.StageController;
import cn.wj.school.common.enums.UiFactory;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.input.KeyCombination;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import org.apache.commons.lang.StringUtils;


public class JteachApp extends Application {

    private static String host = "127.0.0.1";
    private static int port = 7878;

    public static void main(String[] args) throws Exception {
        if (args.length >= 1) {
            host = args[0];
            if (args.length >1 && StringUtils.isNotEmpty(args[1])) {
                port = Integer.valueOf(args[1]);
            }
        }
        launch(args);
    }

    @Override
    public void start(Stage stage) {

        new Thread(() -> new ClientNet(host, port)).start();
        StageController stageController = UiFactory.INSTANCE.getStageController();
        stageController.setPrimaryStage("root", stage);
        Stage loginStage = stageController.loadStage(StageView.id.LOGIN_VIEW, StageView.layout.LOGIN_VIEW,
                StageStyle.DECORATED);
        loginStage.setAlwaysOnTop(true);
        loginStage.setResizable(false);
        loginStage.setFullScreen(true);
        loginStage.setOnCloseRequest((e)->e.consume());
        loginStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
        stageController.setStage(StageView.id.LOGIN_VIEW);
    }
}
